home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / macintosh-c / macc-carbon-demos-nonbinhex.sit / macc-carbon-demos-nonbinhex / chap25-demo-carbon events / ProgressIndicator.c < prev    next >
Text File  |  2001-05-18  |  2KB  |  86 lines

  1. // *******************************************************************************************
  2. // ProgressIndicator.c
  3. // *******************************************************************************************
  4.  
  5. #include "Miscellany.h"
  6.  
  7. // …………………………………………………………………………………………………………………………………………………………………………………………………… global variables
  8.  
  9. extern WindowRef    gWindowRef;
  10. extern RGBColor        gWhiteColour;
  11.  
  12. // ***************************************************************************** doProgressBar
  13.  
  14. void  doProgressBar(void)
  15. {
  16.     DialogRef        dialogRef;
  17.     RgnHandle        visRegionHdl = NewRgn();
  18.     ControlRef    progressBarRef;
  19.     SInt16            statusMax, statusCurrent;
  20.     SInt16             a, b, c;
  21.     Handle            soundHdl;
  22.     Rect                portRect, theRect;
  23.     RGBColor        redColour = { 0xFFFF, 0x0000, 0x0000 };
  24.     
  25.     if(!(dialogRef = GetNewDialog(rDialog,NULL,(WindowRef) -1)))
  26.         ExitToShell();
  27.  
  28.     SetPortDialogPort(dialogRef);
  29.     GetPortVisibleRegion(GetWindowPort(GetDialogWindow(dialogRef)),visRegionHdl);
  30.     UpdateControls(GetDialogWindow(dialogRef),visRegionHdl);
  31.     QDFlushPortBuffer(GetDialogPort(dialogRef),NULL);
  32.  
  33.     SetPortWindowPort(gWindowRef);
  34.     GetWindowPortBounds(gWindowRef,&portRect);
  35.  
  36.     GetDialogItemAsControl(dialogRef,iProgressIndicator,&progressBarRef);
  37.  
  38.     statusMax = 3456;
  39.     statusCurrent = 0;
  40.     SetControlMaximum(progressBarRef,statusMax);
  41.  
  42.     for(a=0;a<9;a++)
  43.     {
  44.         for(b=8;b<423;b+=18)
  45.         {
  46.             for(c=8;c<286;c+=18)
  47.             {
  48.                 if(CheckEventQueueForUserCancel())
  49.                 {
  50.                     soundHdl = GetResource('snd ',rBarkSound);
  51.                     SndPlay(NULL,(SndListHandle) soundHdl,false);
  52.                     ReleaseResource(soundHdl);
  53.                     DisposeDialog(dialogRef);
  54.  
  55.                     EraseRect(&portRect);
  56.                     MoveTo(10,292);
  57.                     RGBForeColor(&gWhiteColour);
  58.                     DrawString("\pOperation cancelled at user request");
  59.  
  60.                     return;
  61.                 }
  62.                 
  63.                 SetRect(&theRect,b+a,c+a,b+17-a,c+17-a);
  64.                 if(a < 3)                                 RGBForeColor(&gWhiteColour);
  65.                 else if(a > 2 && a < 6)  RGBForeColor(&redColour);
  66.                 else if(a > 5)                     RGBForeColor(&gWhiteColour);
  67.                 FrameRect(&theRect);
  68.  
  69.                 QDFlushPortBuffer(GetWindowPort(gWindowRef),NULL);
  70.                 QDFlushPortBuffer(GetDialogPort(dialogRef),NULL);
  71.  
  72.                 SetControlValue(progressBarRef,statusCurrent++);
  73.             }
  74.         }
  75.     }
  76.  
  77.     DisposeRgn(visRegionHdl);
  78.     DisposeDialog(dialogRef);    
  79.     EraseRect(&portRect);
  80.     MoveTo(10,292);
  81.     RGBForeColor(&gWhiteColour);
  82.     DrawString("\pOperation completed");
  83. }
  84.  
  85. // *******************************************************************************************
  86.